home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / DJDEV203.ZIP / include / libc / ttyprvt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-28  |  3.9 KB  |  141 lines

  1. /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
  2. #ifndef __dj_include_libc_ttyprvt_h__
  3. #define __dj_include_libc_ttyprvt_h__
  4.  
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8.  
  9. #ifndef __dj_ENFORCE_ANSI_FREESTANDING
  10.  
  11. #ifndef __STRICT_ANSI__
  12.  
  13. #ifndef _POSIX_SOURCE
  14.  
  15. #include <dpmi.h>
  16. #include <termios.h>
  17. #include <unistd.h>
  18.  
  19. #define _TTY_CTRL(x) ((x) & 0x1f)
  20. #define _TTY_QUEUE_SIZE 2048
  21. #define _TTY_EDITLINE_SIZE ((_TTY_QUEUE_SIZE) / 2)
  22. #define _TTY_EDITLINE_CTRL 0
  23. #define _TTY_EDITLINE_SINGLE 1
  24. #define _TTY_EDITLINE_INVALID -1
  25.  
  26. struct tty_queue
  27. {
  28.   int size;
  29.   unsigned char *top;
  30.   unsigned char *bottom;
  31.   int count;
  32.   unsigned char *rpos;
  33.   unsigned char *wpos;
  34. };
  35.  
  36. struct tty
  37. {
  38.   struct termios __libc_termios;
  39.   struct tty_queue __libc_tty_queue;
  40.   int __libc_tty_status;
  41. };
  42.  
  43. struct tty_editline
  44. {
  45.   int col;
  46.   char flag[_TTY_EDITLINE_SIZE];
  47.   unsigned char buf[_TTY_EDITLINE_SIZE];
  48. };
  49.  
  50. #if !defined (_POSIX_VDISABLE) || (_POSIX_VDISABLE == 0)
  51. #error _POSIX_VDISABLE is undefine or zero.
  52. #endif
  53.  
  54. #define TTYDEFAULT \
  55. {                                    \
  56.   /* struct termios __libc_termios */                    \
  57.   {                                    \
  58.     /* c_cc[] */                            \
  59.     {                                    \
  60.       (cc_t) 0,               /* pad */                 \
  61.       (cc_t) _TTY_CTRL ('d'), /* VEOF */                \
  62.       (cc_t) _POSIX_VDISABLE, /* VEOL */                \
  63.       (cc_t) _TTY_CTRL ('h'), /* VERASE */                \
  64.       (cc_t) _TTY_CTRL ('c'), /* VINTR */                \
  65.       (cc_t) _TTY_CTRL ('u'), /* VKILL */                \
  66.       (cc_t) 1,               /* VMIN */                \
  67.       (cc_t) _TTY_CTRL ('\\'),/* VQUIT */                \
  68.       (cc_t) _TTY_CTRL ('q'), /* VSTART */                \
  69.       (cc_t) _TTY_CTRL ('s'), /* VSTOP */                \
  70.       (cc_t) _TTY_CTRL ('z'), /* VSUSP */                \
  71.       (cc_t) 0,               /* VTIME */                \
  72.     },                                    \
  73.     (tcflag_t) (CS8|CREAD|CLOCAL), /* c_cflag */            \
  74.     (tcflag_t) (BRKINT|ICRNL|IMAXBEL), /* c_iflag */            \
  75.     (tcflag_t) (ISIG|ICANON|ECHO|IEXTEN|ECHOE|ECHOKE|ECHOCTL), /* c_lflag */ \
  76.     (tcflag_t) (OPOST|ONLCR|ONOEOT), /* c_oflag */            \
  77.     (speed_t) (B9600), /* c_ispeed */                    \
  78.     (speed_t) (B9600), /* c_ospeed */                    \
  79.   },                                    \
  80.   /* struct tty_queue __libc_tty_queue */                \
  81.   {                                    \
  82.     _TTY_QUEUE_SIZE,                            \
  83.     __libc_tty_queue_buffer,                        \
  84.     __libc_tty_queue_buffer + _TTY_QUEUE_SIZE,                \
  85.     0,                                    \
  86.     __libc_tty_queue_buffer,                        \
  87.     __libc_tty_queue_buffer,                        \
  88.   },                                    \
  89.   /* __libc_tty_status */                        \
  90.   0,                                    \
  91. }
  92.  
  93. #define t_termios __libc_termios
  94. #define t_iflag __libc_termios.c_iflag
  95. #define t_oflag __libc_termios.c_oflag
  96. #define t_cflag __libc_termios.c_cflag
  97. #define t_lflag __libc_termios.c_lflag
  98. #define t_ispeed __libc_termios.c_ispeed
  99. #define t_ospeed __libc_termios.c_ospeed
  100. #define t_cc __libc_termios.c_cc
  101. #define t_status __libc_tty_status
  102.  
  103. #define t_size __libc_tty_queue.size
  104. #define t_top __libc_tty_queue.top
  105. #define t_bottom __libc_tty_queue.bottom
  106. #define t_count __libc_tty_queue.count
  107. #define t_rpos __libc_tty_queue.rpos
  108. #define t_wpos __libc_tty_queue.wpos
  109.  
  110. #define _TS_LNCH 0x01 /* next character is literal */
  111. #define _CC_EQU(v,c) (((c) == (unsigned char) __libc_tty_p->t_cc[(v)])    \
  112.               && ((c) != (unsigned char) _POSIX_VDISABLE))
  113. #define _CC_NEQU(v,c) (((c) != (unsigned char)__libc_tty_p->t_cc[(v)])    \
  114.                && ((c) != (unsigned char) _POSIX_VDISABLE))
  115.  
  116. /* internal buffers */
  117. extern unsigned char __libc_tty_queue_buffer[];
  118. extern struct tty __libc_tty_internal;
  119. extern struct tty *__libc_tty_p;
  120. extern struct tty_editline __libc_tty_editline;
  121.  
  122. /* termios hooks */
  123. extern ssize_t (*__libc_read_termios_hook)(int handle, void *buffer, size_t count,
  124.                               ssize_t *rv);
  125. extern ssize_t (*__libc_write_termios_hook)(int handle, const void *buffer, size_t count,
  126.                         ssize_t *rv);
  127. extern int __libc_termios_hook_common_count;
  128.  
  129. /* functions */
  130. void __libc_termios_init (void);
  131.  
  132. #endif /* !_POSIX_SOURCE */
  133. #endif /* !__STRICT_ANSI__ */
  134. #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
  135.  
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139.  
  140. #endif /* !__dj_include_libc_ttyprvt_h__ */
  141.